const path = require('path');
const {
    name,type,port
} = require('./src/libs/config');


function resolve(dir) {
    //path.join(__dirname)设置绝对路径
    return path.join(__dirname, dir)
}
module.exports = {
    publicPath: "/"+type+"/"+name,
    // 输出文件目录
    outputDir: "build/"+type+"-"+name,
    chainWebpack: (config) => {
        config.resolve.alias
            //set第一个参数：设置的别名，第二个参数：设置的路径
            .set('@', resolve('./src'))
            .set('styles', resolve('./src/styles'))
            .set('libs', resolve('./src/libs'))
            .set('views', resolve('./src/views'))
            .set('components', resolve('./src/components'));

        config.module
            .rule('fonts')
            .test(/.(ttf|otf|eot|woff|woff2)$/)
            .use('url-loader')
            .loader('url-loader')
            .tap(options => ({
                name: '/fonts/[name].[hash:8].[ext]'
            }))
            .end()
    },
    configureWebpack: {
        output: {
            library: `${type}_${name}`,
            libraryTarget: 'umd', // 把子应用打包成 umd 库格式
            jsonpFunction: `webpackJsonp_${type}_${name}`,
        },
        externals: {
            'vue': 'Vue',
            'vue-router': 'VueRouter',
            'vuex': 'Vuex',
            'axios': 'axios',
            'element-ui': 'element-ui',
        }
    },
    //关闭SourceMap
    productionSourceMap: false,
    // 关闭eslint语法等检验
    lintOnSave: false,
    devServer: {
        // disableHostCheck: true
        // 配置自动启动浏览器
        open: false,
        headers: {
            'Access-Control-Allow-Origin': '*',
        },
    }
}